/**
 * 
 */
package sailing.resource;

import java.net.URL;
import java.util.Map;

import javax.swing.Icon;
import javax.swing.ImageIcon;

import cjlite.logger.Logger;
import cjlite.utils.Maps;

/**
 * @author kevin
 * 
 */
public class Resource {
	private static Logger logger = Logger.thisClass();
	private static String rel_url = "/sailing/resource";

	private static Map<String, ImageIcon> imageResourceMap = Maps.newHashMap();

	public static ImageIcon getImageIcon(String filename) {
		String path = rel_url + filename;
		try {
			ImageIcon ii = imageResourceMap.get(path);
			if (ii == null) {
				ii = new ImageIcon(Resource.class.getResource(path));
				imageResourceMap.put(path, ii);
			}

			return ii;
		} catch (Throwable t) {
			logger.error("error on loading Icon image {0} within full path {1}", t, filename, path);
		}
		return null;
	}

	public static URL getResource(String bg9Img) {
		return Resource.class.getResource(rel_url + bg9Img);
	}
}
